dict1 = {}  # 结论：这个dict1是Class1的所有类实例共享的


class Class1(object):
    def __init__(self, name):
        self.name = name
        dict1[name] = name

    def print_value(self):
        print(self.name, dict1)


class Class2:
    """setattr测试: 可以正确处理list类型"""
    v_keys = ["v1", "v2"]

    def __init__(self):
        self.v1 = [1, 2]
        self.v2 = "aaa"

    def print_value(self):
        print(self.v1, self.v2)

    def get_data(self):
        d = {}
        for key in self.v_keys:
            d[key] = getattr(self, key)
        return d

    def set_data(self, data):
        for key, v in data.items():
            setattr(self, key, v)
